﻿using System;

namespace AirPlanGame
{
   internal class Program
    {
        //棋盘，定义为全局变量
        private static int[] Maps = new int[100];
        //玩家的姓名
        private static string[] PlayerNames = new string[2];
        //玩家走棋的坐标
        private static int[] PlayerPos = new int[2];
        //两个玩家的状态默认为false
        private static bool[] Flags = new bool[2];
       private static void Main(string[] args)
        {
            #region 1.画游戏开头 GameShow()
            //1.画游戏开头 GameShow()
            GameShow();
            #endregion
            #region 2.输入玩家姓名（变量 PlayerName[])
            //2.输入玩家姓名（变量 PlayerName[])
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("请输入玩家A的姓名：");
            PlayerNames[0] = Console.ReadLine();
            //检查用户输入的正确性
            while(string.IsNullOrEmpty(PlayerNames[0]))
            {
                Console.WriteLine("玩家A的姓名不能为空，请输入玩家A的姓名:");
                PlayerNames[0] = Console.ReadLine();
            }
            Console.WriteLine("请输入玩家B的姓名：");
            PlayerNames[1] = Console.ReadLine();
            while(string.IsNullOrEmpty(PlayerNames[1])||PlayerNames[1]==PlayerNames[0])
            {
                if(string.IsNullOrEmpty(PlayerNames[1]))
                {
                    Console.WriteLine("玩家B的姓名不能为空，请输入玩家B的姓名: ");
                    PlayerNames[1] = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("玩家B的姓名不能和玩家A相同，请输入玩家姓名：");
                    PlayerNames[1] = Console.ReadLine();
                }
            }
           
            //打印玩家姓名
            Console.Clear();
            GameShow();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("{0}的士兵用A表示", PlayerNames[0]);
            Console.WriteLine("{0}的士兵用B表示", PlayerNames[1]);
            #endregion
            //3.初始化飞行棋地图 InitialMap()
            InitialMap();
            //4.显示地图 DrawMap()
            DrawMap();
            //5.循环走棋 只要任意玩家没有走到地图的最后一个坐标 每次走棋执行相应的游戏规则 PlaiGame()

            //当玩家A和玩家B没有一个人在终点的时候，两个晚会不停的走棋
            while (PlayerPos[0] < 99 && PlayerPos[1]<99)
            {
                //根据状态，切换玩家状态来轮流走棋

                if (!Flags[0])
                    PlayGame(0);
                else
                    Flags[0] = false;
                //判断是否游戏完成
                if(PlayerPos[0]>=99)
                {
                    //玩家1赢，游戏结束
                    Console.WriteLine("玩家{0}用智慧赢了玩家{1}", PlayerNames[0], PlayerNames[1]);
                    break;
                }
                //根据状态，切换玩家状态来轮流走棋

                if (!Flags[1])
                    PlayGame(1);
                else
                    Flags[1] = false;
                //判断是否游戏完成
                if (PlayerPos[0] >= 99)
                {
                    //玩家1赢，游戏结束
                    Console.WriteLine("玩家{0}用智慧赢了玩家{1}", PlayerNames[1], PlayerNames[0]);
                    break;
                }
            }

            //6.显示胜利画面 

            //结束
            Console.ReadKey();
        }
        /// <summary>
        /// 开头画面
        /// </summary>
        public static void GameShow()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("********************************************");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("********************************************");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("********************************************");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("********************************************");
            Console.WriteLine("*******软件工程演示项目：飞行棋1.0**********");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("********************************************");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("********************************************");
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("********************************************");
        }
        
        
        /// <summary>
        /// 初始化棋盘
        /// </summary>
        public static void InitialMap()
        {
            //幸运轮盘
            int[] luckyturn = { 2, 12, 8,15, 44, 88 };
            for (var i = 0; i < luckyturn.Length; i++)
            {
                Maps[luckyturn[i]] = 1;//值1表示幸运轮盘
            }
            //地雷
            int[] mines = { 16, 22, 33, 44, 55, 3, 6 };
            for (var i = 0; i < mines.Length; i++)
            {
                Maps[mines[i]] = 2;//值2 表示地雷
            }
            //暂停
            int[] pames = { 5,20,29,34,64,50,89 };
            for (var i=0;i<pames.Length;i++)
            {
                Maps[pames[i]] = 3;//值3表示暂停
            }
            //时空隧道
            int[] tum1 = { 20, 30, 1, 40, 50, 60, 70 };
            for (var i = 0; i < tum1.Length; i++)
            {
                Maps[tum1[i]] = 4;//值4表示时空隧道
            }
        }
        
        /// <summary>
        /// 画出地图
        /// </summary>
        public static void DrawMap()
        {
            Console.WriteLine("图例:幸运轮盘:◎地雷:☆暂停:▲时空隧道:卐");
            //第一横行
            for (var i = 0; i < 30; i++)
                Console.Write(DrawMapPos(i));
            Console.WriteLine();

            //第一竖行
            for (var i = 30; i < 35; i++)
            {
                for (var j = 0; j < 29; j++)
                {
                    Console.Write("  ");
                }

                Console.Write(DrawMapPos(i));
                Console.WriteLine();
            }

            //第二横行
            for (var i = 63; i >= 35; i--)
                Console.Write(DrawMapPos(i));

            //第二竖行
            for (var i = 64; i <= 69; i++)
                Console.WriteLine(DrawMapPos(i));

            //第三横行
            for (var i = 70; i <= 99; i++)
                Console.Write(DrawMapPos(i));

            //结束换行
            Console.WriteLine();
        }
        /// <summary>
        /// 画棋盘的方法
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public static string DrawMapPos(int i)
        {
            string str = "";
            //如果A B 重合 显示<>
            if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)
                str = "<>";
            else if (PlayerPos[0] == i)
                str = "A";
            else if (PlayerPos[1] == i)
                str = "B";
            else 
            {
                //正常位置○ 幸运轮盘:◎地雷:☆暂停:▲时空隧道:卐
                switch (Maps[i])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        str = "○";
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Green;
                        str = "◎";
                        break;

                    case 2:
                        Console.ForegroundColor = ConsoleColor.Red;
                        str = "☆";
                        break;

                    case 3:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        str = "▲";
                        break;

                    case 4:
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        str = "卐";
                        break;

                }
            }
            
            return str;
        }

        /// <summary>
        /// 玩游戏，走棋
        /// </summary>
        /// <param name="player"></param>
        public static void PlayGame(int player)
        {
            //正常走
        }
    }
}
